﻿@model IEnumerable<IniTechCaash.WebApplication.Models.FinanceAccountDetailsViewModel>
@using IniTechCaash.Domain.Entities

@{
    ViewBag.Title = "Trial Balance";
    String timeStamp = DateTime.Now.ToString("MM-dd-yyyy h:mmtt");
    decimal debits = 0.00m, credits = 0.00m;
    if (Model.Where(a => a.Type.GetNormalSide() == NormalSide.Debit).Count() > 0)
    {
        debits = Model.Where(a => a.Type.GetNormalSide() == NormalSide.Debit).Select(a => a.Balance).Aggregate((a, b) => a + b);
    }
    if (Model.Where(a => a.Type.GetNormalSide() == NormalSide.Credit).Count() > 0)
    {
        credits = Model.Where(a => a.Type.GetNormalSide() == NormalSide.Credit).Select(a => a.Balance).Aggregate((a, b) => a + b);
    }
}

<div>
    <h3>IniTech</h3>
    <h4>Trial Balance</h4>
    <p>As of @DateTime.Now.ToString("MMM ddd d HH:mm yyyy")</p>
</div>

<table class="table">
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th class="text-right">DR</th>
        <th class="text-right">CR</th>
    </tr>
@foreach (var item in Model) {
    <tr>
        <td>
            @Html.ActionLink(String.Join("-", item.Descriptive, item.Number), "Details", new { id = item.Id})
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        @if (item.Type.GetNormalSide() == NormalSide.Debit)
        {
            <td class="text-right">
                @item.Balance.ToString("#,#.00#;(#,#.00#);0")
            </td>
            <td class="text-right"></td>
        }
        else
        {
            <td class="text-right"></td>
            <td class="text-right">
                @item.Balance.ToString("#,#.00#;(#,#.00#);0")
            </td>
        }
    </tr>
}
<tr>
    <td colspan="2" style="text-align:right">Totals:</td>
    <td class="text-right">@debits.ToString("#,#.00#;(#,#.00#);0")</td>
    <td class="text-right">@credits.ToString("#,#.00#;(#,#.00#);0")</td>
</tr>
</table>

<hr />

@Html.ActionLink("Back To List", "Index")
